package tech.yunland.shop.domain.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.moyuer.bsf.domain.model.AbstractEntity;
import com.moyuer.bsf.domain.model.User;

import javax.persistence.*;
import java.math.BigDecimal;
import java.util.Date;

/**
 * Created by v on 17-7-3.
 */
@Entity
@Table(name = "score")
public class Score extends AbstractEntity {

    @JSONField(serialize = false)
    @ManyToOne
    private User students;

    @JSONField(serialize = false)
    @ManyToOne
    private Exam exam;

    @Transient
    private Date examTime;

    @Transient
    private String uname;

    @Transient
    private String ename;

    @Column
    private BigDecimal score = BigDecimal.ZERO;

    public Date getExamTime() {
        if (this.exam != null) {
            return this.exam.getExamTime();
        }
        return examTime;
    }

    public void setExamTime(Date examTime) {
        this.examTime = examTime;
    }

    public String getUname() {
        if (this.students != null) {
            return this.students.getName();
        }
        return uname;
    }

    public void setUname(String uname) {
        this.uname = uname;
    }

    public String getEname() {
        if (this.exam != null) {
            return this.exam.getLessons().getLname();
        }
        return ename;
    }

    public void setEname(String ename) {
        this.ename = ename;
    }

    public User getStudents() {
        return students;
    }

    public void setStudents(User students) {
        this.students = students;
    }

    public Exam getExam() {
        return exam;
    }

    public void setExam(Exam exam) {
        this.exam = exam;
    }

    public BigDecimal getScore() {
        return score;
    }

    public void setScore(BigDecimal score) {
        this.score = score;
    }
}
